/**
 * 功能描述
 */
define(function (require, exports, module) {
    //引入视图基类
    var ELView = require("elview");

    //assets
    var template = require("./assets/tpl/contractaward_main.tpl");
    require("./assets/css/contractaward_main.css");

    //business

    //component
    var ContractAwardSubnav = require("./component/ContractAwardSubnav");
    var ContractAwardForm = require("./component/ContractAwardFormCom");
    var ContractAwardGrid = require("./component/ContractAwardGrid");
    
    var tools = require("tools");
    var Dialog = require("dialog");
    //constant

    //handler

    //store
    var aw = require("ajaxwrapper");
    var App = ELView.extend({
        attrs: {
            template: template
        },
        initComponent: function (params, widget) {
        	ContractAwardSubnav.initComponent(params, widget);
        	ContractAwardForm.initComponent(params, widget);
        	ContractAwardGrid.initComponent(params, widget);
        },
        afterInitComponent: function (params, widget) {
        	var subnav=widget.get("subnav");
        	var grid=widget.get("grid");
            grid.refresh();
        },
        addMemberFromContractAward: function(params,widget){
        	//从新增会员节点返回
        	aw.ajax({
        		url:"api/personalinfo/query",
        		data: {
        			"pkPersonalInfo":params.member.personalInfo.pkPersonalInfo,
        			fetchProperties: "*," +
        					"contactAddresses.*," +
        					"contactAddresses.communityret.name," +
        					"contactAddresses.address.fullName"
        				
        		},
        		success: function(rets){
        			var form = widget.get("form");
        			var ret = rets[0];
        			form.setValue("name",{
        				personalInfo:{
        					name: ret.name
        				}
        			});
                	form.setValue("pkMember",params.member.pkMember);
        			//身份证号
        			form.setValue("idNumber",ret.idNumber);
        			//性别
        			form.setValue("sex",ret.sex.key);	
        			//联系方式
        			form.setValue("mobilePhone",ret.mobilePhone);
        			//生日 年龄
        			var birthdays = ret.birthday
        			var birthday = moment(birthdays).format('YYYY-MM-DD');
        			var age = tools.getAgeByBirthdate(birthday);
        			form.setValue("birthday",birthday);
        			form.setValue("age",age);
//        			//省/市/区（县）
//        			form.setValue("address",ret.contactAddresses[0].address.fullName);
//        			//详细地址
//        			var detailAddress =ret.contactAddresses[0].communityret.name + ret.contactAddresses[0].buildingNumber+ "号楼" + ret.contactAddresses[0].unitNumber + "单元" + ret.contactAddresses[0].doorNumber + "室";
        			
//        			form.setValue("detailAddress",detailAddress);
        			widget.show([".J-form"]).hide([".J-grid"]);
					widget.get("subnav").hide(["add","search","status","servicePoint","dateRange"]).show(["back"]);
					Dialog.close();
        		}
        	});
        }
    });

    module.exports = App;
});
